﻿Imports System.Data
Imports System.Data.OleDb
Imports geraLaudosAutomatico.conexao
Imports System.Text
Public Class relatorio_reciboDAO


    Private sql As New StringBuilder
    Private objConn As New conexao
    Private i As Integer
    Private relatorio_recibo As New relatorio_reciboVO
    Private funcionario_recibo As New funcionario_reciboBO
    Private usuario As New usuarioBO
    Private secao As New secaoBO

    Public Function getRelatorioRecibos() As Generic.List(Of relatorio_reciboVO)

        sql.Clear()

        With sql
            .Append("SELECT *FROM RELATORIO_RECIBO ORDER BY ID_RELATORIO_RECIBO")
        End With

        Dim oReader As OleDbDataReader
        Dim lista As New Generic.List(Of relatorio_reciboVO)


        Try
            Dim oComando As New OleDbCommand(sql.ToString, objConn.abreConexao)

            oReader = oComando.ExecuteReader

            While oReader.Read

                relatorio_recibo = New relatorio_reciboVO
                relatorio_recibo.ID_RELATORIO_RECIBO = oReader("ID_RELATORIO_RECIBO")
                relatorio_recibo.DATA_RECIBO = oReader("DATA_RECIBO")
                relatorio_recibo.FUNCIONARIO_RECIBO = funcionario_recibo.getFuncionarioRecibo(oReader("ID_FUNCIONARIO"))
                relatorio_recibo.USUARIO = usuario.getUsuario(oReader("ID_USUARIO"))
                relatorio_recibo.SECAO = secao.getSecao(oReader("ID_SECAO"))
                lista.Add(relatorio_recibo)

            End While

            Return lista

        Catch ex As Exception

            Throw ex

        Finally

            objConn.fechaConexao()

        End Try

    End Function



    Public Function getRelatorioRecibo(ByVal id_relatorio_recibo As Integer) As relatorio_reciboVO

        sql.Clear()

        With sql
            .Append("SELECT *FROM RELATORIO_RECIBO ")
            .Append(" WHERE ID_RELATORIO_RECIBO = " & id_relatorio_recibo)

        End With

        Dim oReader As OleDbDataReader
        Try
            Dim oComando As New OleDbCommand(sql.ToString, objConn.abreConexao)

            oReader = oComando.ExecuteReader

            While oReader.Read

                relatorio_recibo = New relatorio_reciboVO
                relatorio_recibo.ID_RELATORIO_RECIBO = IIf(IsDBNull(oReader("ID_RELATORIO_RECIBO")), Nothing, oReader("ID_RELATORIO_RECIBO"))
                relatorio_recibo.DATA_RECIBO = IIf(IsDBNull(oReader("DATA_RECIBO")), Nothing, oReader("DATA_RECIBO"))
                relatorio_recibo.FUNCIONARIO_RECIBO = IIf(IsDBNull(oReader("ID_FUNCIONARIO")), Nothing, funcionario_recibo.getFuncionarioRecibo(oReader("ID_FUNCIONARIO")))
                relatorio_recibo.USUARIO = IIf(IsDBNull(oReader("ID_USUARIO")), Nothing, usuario.getUsuario(oReader("ID_USUARIO")))
                relatorio_recibo.SECAO = IIf(IsDBNull(oReader("ID_SECAO")), Nothing, secao.getSecao(oReader("ID_SECAO")))

            End While

            Return relatorio_recibo

        Catch ex As Exception

            Throw ex

        Finally

            objConn.fechaConexao()

        End Try

    End Function

End Class
